(function ($) {
    "use strict";

    let windowWidth = window.innerWidth;
    // Spinner
    var spinner = function () {
        setTimeout(function () {
            if ($('#spinner').length > 0) {
                $('#spinner').removeClass('show');
            }
        }, 1);
    };
    spinner(0);


    // Initiate the wowjs
    new WOW().init();


    // Sticky Navbar
    $(window).scroll(function () {
        if ($(this).scrollTop() > 70) {
            $('.sticky-top').addClass(['shadow-sm', 'bg-white']).css('top', '0px');
            $('#scrollable .nav-link').removeClass('text-white').addClass('text-dark');
            $('#lang-svg').attr('src', '/static/Svg/language.svg');
            // $('#logo').attr('src', '/static/logo-black.png')
        } else {
            if (windowWidth < 992) return
            $('.sticky-top').removeClass(['shadow-sm', 'bg-white']).css('top', '-100px');
            $('#scrollable .nav-link').addClass('text-white').removeClass('text-dark');
            $('#lang-svg').attr('src', '/static/Svg/language-white.svg');
            // $('#logo').attr('src', '/static/logo-white.png')
        }
    });
    if (windowWidth < 992) {
        $('.sticky-top').addClass(['shadow-sm', 'bg-white']);
        $('.scrollable').addClass(['shadow-sm', 'bg-white']);
        $('.navbar-nav a').removeClass('text-white').addClass('text-dark')
        $('.change-lange').removeClass('text-white').addClass('text-dark')
        $('#navbarCollapse').removeClass('collapse navbar-collapse').addClass('offcanvas offcanvas-end').css('width', '70%')
        $('#logo').css('max-height', '35px')
    }

    // Car Categories
    $("#newsSwiper").owlCarousel({
        autoplay: true,
        smartSpeed: 1000,
        dots: true,
        loop: true,
        margin: 25,
        nav : false,
        responsiveClass: true,
        items: 1
    });



    // Facts counter
    $('[data-toggle="counter-up"]').counterUp({
        delay: 5,
        time: 2000
    });


   // Back to top button
   $(window).scroll(function () {
    if ($(this).scrollTop() > 300) {
        $('.back-to-top').fadeIn('slow');
    } else {
        $('.back-to-top').fadeOut('slow');
    }
    });
    $('.back-to-top').click(function () {
        $('html, body').animate({scrollTop: 0}, 1500, 'easeInOutExpo');
        return false;
    });

    // 轮播图
    $(document).ready(function () {
        let mySwiper = new Swiper('.swiper-container', {
            loop: true,
            // 如果需要分页器
            pagination: '.swiper-pagination',
            // 如果需要前进后退按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            slidesPerView: 3,
            spaceBetween: 30,
            centeredSlides: true,
            // bulletClass: 'bulletClass',
            bulletActiveClass: 'my-bullet-active',
        })
    })

})(jQuery);

